import pandas as pd
from sklearn.preprocessing import MinMaxScaler

data = pd.read_csv("Code\process_wine.csv",index_col=0)

#print(data.head(10))

data1 = data.iloc[:, :-1]  # 选择除最后一列外的所有列
#print(data1)

# 最大最小归一化
scaler = MinMaxScaler()
data1_normalized = scaler.fit_transform(data1)

# 转换为DataFrame并查看结果
data1_normalized = pd.DataFrame(data1_normalized, index=data1.index, columns=data1.columns)
print("归一化后数据前5行：")
print(data1_normalized.head(5))
# print("\n归一化后数据统计量：")
# print(data1_normalized.describe())

# 保存归一化后的数据到新CSV文件
output_path = r"Code\processed_wine.csv"  # 保存路径
data1_normalized.to_csv(output_path)

print(f"归一化后的数据已保存至：{output_path}")
print("归一化后数据前5行：")
print(data1_normalized.head(5))